package com.lb.strategy;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @ClassName： StrategyContext
 * @Description：
 * @Author: 蓝莲花
 * @Date： 2021/7/11 下午12:39
 * @Version： V1.0
 */
@Service
public class StrategyContext {
    @Autowired
    private final Map<String, CommonStrategy> strategyMap = new ConcurrentHashMap<>();

    public StrategyContext(Map<String, CommonStrategy> strategyMap) {
        this.strategyMap.clear();
        strategyMap.forEach((k,v) -> this.strategyMap.put(k,v));
    }

    public void handleBiz(String key,Object o) {
        strategyMap.get(key).handle(o);
    }
}
